package com.hefeng.wx.controller;

import com.hefeng.system.api.domain.SysUser;
import com.hefeng.wx.crawler.GetZoningCode;
import com.hefeng.wx.domain.SysAreasHainan;
import com.hefeng.wx.domain.entity.ProvinceCodeEntity;
import com.hefeng.wx.service.SysAreasService;
import com.hefeng.wx.service.WxUserService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    WxUserService wxUserService;
    @Autowired
    SysAreasService sysAreasService;
    @GetMapping("/list")
    public String list(SysUser user)
    {
        GetZoningCode getZoningCode =new GetZoningCode();
        List<ProvinceCodeEntity>list=getZoningCode.seveAeras();
        System.out.println(list.size());
        //System.out.println(wxUserService.getWxuser().toString());
        list.forEach(stu->{
            SysAreasHainan areas=new SysAreasHainan();
            areas.setCode(stu.getProvinceCode());
            areas.setPCode(stu.getProvinceCode());
            areas.setName(stu.getProvinceName());
            areas.setLevel(1);
            areas.setCreatedTime(new Date());
            sysAreasService.seve(areas);
            stu.getCityCodeEntities().forEach(c->{
                SysAreasHainan areas1=new SysAreasHainan();
                areas1.setCode(c.getCityCode());
                areas1.setPCode(stu.getProvinceCode());
                areas1.setName(c.getCityName());
                areas1.setLevel(2);
                areas1.setCreatedTime(new Date());
                sysAreasService.seve(areas1);
                c.getAreaCodeEntities().forEach(a->{
                    SysAreasHainan areas2=new SysAreasHainan();
                    areas2.setCode(a.getAreaCode());
                    areas2.setPCode(c.getCityCode());
                    areas2.setName(a.getAreaName());
                    areas2.setLevel(3);
                    areas2.setCreatedTime(new Date());
                    sysAreasService.seve(areas2);
                    a.getStreetCodeEntities().forEach(s->{
                        SysAreasHainan areas3=new SysAreasHainan();
                        areas3.setCode(s.getStreetCode());
                        areas3.setPCode(a.getAreaCode());
                        areas3.setName(s.getStreetName());
                        areas3.setLevel(4);
                        areas3.setCreatedTime(new Date());
                        sysAreasService.seve(areas3);
                    });
                });
            });
        });
        //sysAreasService.seve(null);
        System.out.println("请求成功");
        return "请求成功";


    }
    @PostMapping("/testJson")
    public String testJson(JSONObject object){
        System.out.println(object.toString());
    return "true";
    }

}
